#获取矩形的n行m列
data = input()
n,m = int(data.split()[0]),int(data.split()[1])

#获取矩形
rectangle = []
for i in range(n):
    line = input().split()
    rectangle.append([int(num) for num in line])
    
#获取每行之和
line_sums = [sum(line) for line in rectangle]
#获取每列之和
column_sums = [0 for _ in range(m)]
for i in range(m):
    for j in range(n):
        column_sums[i] += rectangle[j][i]
#所有元素之和
total_sums = sum(line_sums)
        
min_diff = total_sums
for data in (line_sums,column_sums):
    pre_sum = 0
    for num in data:
        pre_sum += num
        min_diff = min(min_diff,abs(total_sums-pre_sum*2))
print(min_diff)

    

        